package com.sugon.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.ModuleMaintainOptionsHisDao;
import com.sugon.entity.ModuleMaintainOptionsEntity;
import com.sugon.entity.ModuleMaintainOptionsHisEntity;
import com.sugon.service.ModuleMaintainOptionsHisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 模具维护规程选项变更履历Service实现类
 *
 * @author sugon
 * @date 2020-11-27 14:26:56
 */
@Service("moduleMaintainOptionsHisService")
public class ModuleMaintainOptionsHisServiceImpl implements ModuleMaintainOptionsHisService {
    @Autowired
    private ModuleMaintainOptionsHisDao moduleMaintainOptionsHisDao;

    @Override
    public void recordHistory(String actionType, ModuleMaintainOptionsEntity moduleMaintainOptions) {
        ModuleMaintainOptionsHisEntity moduleMaintainOptionsHis = new ModuleMaintainOptionsHisEntity();
        CopyOptions copyOptions = CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true);
        BeanUtil.copyProperties(moduleMaintainOptions, moduleMaintainOptionsHis,copyOptions);
        moduleMaintainOptionsHis.setRecordId(moduleMaintainOptions.getId());
        moduleMaintainOptionsHis.setOperator(moduleMaintainOptions.getUpdateUser());
        moduleMaintainOptionsHis.setOperateDate(moduleMaintainOptions.getUpdateDate());
        moduleMaintainOptionsHis.setActionType(actionType);
        save(moduleMaintainOptionsHis);
    }

    @Override
    public ModuleMaintainOptionsHisEntity queryObject(String id) {
        return moduleMaintainOptionsHisDao.queryObject(id);
    }

    @Override
    public List<ModuleMaintainOptionsHisEntity> queryList(Map<String, Object> map) {
        return moduleMaintainOptionsHisDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return moduleMaintainOptionsHisDao.queryTotal(map);
    }

    @Override
    public int save(ModuleMaintainOptionsHisEntity moduleMaintainOptionsHis) {
        moduleMaintainOptionsHis.setId(RandomUtil.randomString(32));
        return moduleMaintainOptionsHisDao.save(moduleMaintainOptionsHis);
    }

    @Override
    public int update(ModuleMaintainOptionsHisEntity moduleMaintainOptionsHis) {
        return moduleMaintainOptionsHisDao.update(moduleMaintainOptionsHis);
    }

    @Override
    public int delete(String id) {
        return moduleMaintainOptionsHisDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return moduleMaintainOptionsHisDao.deleteBatch(ids);
    }
}
